package edu.szte.ovrt.datahandler.model;

public class Item extends ModelBase {
	private final Section m_parent;
	private String m_key;
	private String m_value;

	public Item(final Section parent, final String key, final String value) {
		m_parent = parent;
		setKey(key);
		setValue(value);
	}

	public Item(final Section parent, final String key) {
		this(parent, key, "");
	}

	public void setKey(final String key) {
		m_key = key;
	}

	public String getKey() {
		return m_key;
	}

	public void setValue(final String value) {
		m_value = value;
	}

	public String getValue() {
		return m_value;
	}

	public Section getParent() {
		return m_parent;
	}

	@Override
	public String getName() {
		return getKey();
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj == null || !(obj instanceof Item)) { return false; }
		final Item other = (Item) obj;
		return getKey().equals(other.getKey()) && getValue().equals(other.getValue());
	}

	@Override
	public int hashCode() {
		return getKey().hashCode() ^ getValue().hashCode();
	}

	@Override
	public String toString() {
		return String.format("Item: {0} => {1}", getKey(), getValue());
	}

}
